using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Common;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using SExperiment;

namespace Report
{
	public class ExcelOperator
	{
		public static bool PrintExcel(string excelFile, bool landscape = false)
		{
			bool result = false;
			PrintDialog printDialog = new PrintDialog();
			printDialog.PrinterSettings.DefaultPageSettings.Landscape = landscape;
			if (printDialog.ShowDialog() == DialogResult.OK)
			{
				object obj = null;
				Type type = null;
				try
				{
					type = Type.GetTypeFromProgID("Excel.Application");
					if (type == null)
					{
						Log.WriteLine("没有安装Excel。");
						return false;
					}
					obj = Activator.CreateInstance(type);
					object obj2 = obj.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, Type.DefaultBinder, obj, null);
					object obj3 = obj2.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, obj2, new object[3] { excelFile, true, true });
					object obj4 = obj3.GetType().InvokeMember("Worksheets", BindingFlags.GetProperty, Type.DefaultBinder, obj3, null);
					object obj5 = obj4.GetType().InvokeMember("Item", BindingFlags.GetProperty, Type.DefaultBinder, obj4, new object[1] { 1 });
					object obj6 = obj5.GetType().InvokeMember("PageSetup", BindingFlags.GetProperty, Type.DefaultBinder, obj5, null);
					obj6.GetType().InvokeMember("Orientation", BindingFlags.SetProperty, Type.DefaultBinder, obj6, new object[1] { (!landscape) ? XlPageOrientation.xlPortrait : XlPageOrientation.xlLandscape });
					obj5.GetType().InvokeMember("PrintOut", BindingFlags.InvokeMethod, Type.DefaultBinder, obj3, new object[5]
					{
						Type.Missing,
						Type.Missing,
						1,
						false,
						printDialog.PrinterSettings.PrinterName
					});
					obj2.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, obj3, new object[1] { false });
					result = true;
				}
				catch (Exception ex)
				{
					Log.WriteLine(ex.StackTrace);
				}
				finally
				{
					if (type != null && obj != null)
					{
						type.InvokeMember("Quit", BindingFlags.InvokeMethod, null, obj, null);
					}
				}
			}
			return result;
		}

		public static bool ExportToXPS(string excelFile, string xpsFile, bool Landscape = false)
		{
			bool result = false;
			object obj = null;
			Type type = null;
			try
			{
				type = Type.GetTypeFromProgID("Excel.Application");
				if (type == null)
				{
					Log.WriteLine("没有安装Excel。");
					return false;
				}
				obj = Activator.CreateInstance(type);
				object obj2 = obj.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, Type.DefaultBinder, obj, null);
				object obj3 = obj2.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, obj2, new object[3] { excelFile, true, true });
				object obj4 = obj3.GetType().InvokeMember("Worksheets", BindingFlags.GetProperty, Type.DefaultBinder, obj3, null);
				object obj5 = obj4.GetType().InvokeMember("Item", BindingFlags.GetProperty, Type.DefaultBinder, obj4, new object[1] { 1 });
				object obj6 = obj5.GetType().InvokeMember("PageSetup", BindingFlags.GetProperty, Type.DefaultBinder, obj5, null);
				obj6.GetType().InvokeMember("Orientation", BindingFlags.SetProperty, Type.DefaultBinder, obj6, new object[1] { (!Landscape) ? XlPageOrientation.xlPortrait : XlPageOrientation.xlLandscape });
				obj5.GetType().InvokeMember("ExportAsFixedFormat", BindingFlags.InvokeMethod, null, obj3, new object[2]
				{
					XlFixedFormatType.xlTypeXPS,
					xpsFile
				});
				obj2.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, obj3, new object[1] { false });
				result = true;
			}
			catch (Exception)
			{
			}
			finally
			{
				if (type != null && obj != null)
				{
					type.InvokeMember("Quit", BindingFlags.InvokeMethod, null, obj, null);
				}
			}
			return result;
		}

		public static void ExportToExcel(string file, List<List<string>> data)
		{
			CreateNewExcel(file, "Data");
			using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(file, true))
			{
				Worksheet worksheet = spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet;
				SheetData firstChild = worksheet.GetFirstChild<SheetData>();
				uint num = 1u;
				foreach (List<string> datum in data)
				{
					Row row = new Row();
					row.RowIndex = num++;
					Row row2 = row;
					foreach (string item in datum)
					{
						double result;
						bool flag = double.TryParse(item, out result);
						Cell cell = new Cell();
						cell.CellValue = new CellValue(item);
						cell.DataType = (flag ? CellValues.Number : CellValues.String);
						Cell cell2 = cell;
						row2.Append(cell2);
					}
					firstChild.Append(row2);
				}
				worksheet.Save();
			}
		}

		public static void ExportToExcel(Experiment experiment, string path)
		{
			CreateNewExcel(path, experiment.Name);
			using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(path, true))
			{
				Worksheet worksheet = spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet;
				SheetData firstChild = worksheet.GetFirstChild<SheetData>();
				uint num = 1u;
				Row row = new Row();
				row.RowIndex = num++;
				Row row2 = row;
				Cell cell = new Cell();
				cell.CellValue = new CellValue(Utility.GetMessage("reaction_well"));
				cell.DataType = CellValues.String;
				Cell cell2 = cell;
				row2.Append(cell2);
				Cell cell3 = new Cell();
				cell3.CellValue = new CellValue(Utility.GetMessage("tube_name"));
				cell3.DataType = CellValues.String;
				cell2 = cell3;
				row2.Append(cell2);
				Cell cell4 = new Cell();
				cell4.CellValue = new CellValue(Utility.GetMessage("Target"));
				cell4.DataType = CellValues.String;
				cell2 = cell4;
				row2.Append(cell2);
				Cell cell5 = new Cell();
				cell5.CellValue = new CellValue(Utility.GetMessage("Type"));
				cell5.DataType = CellValues.String;
				cell2 = cell5;
				row2.Append(cell2);
				Cell cell6 = new Cell();
				cell6.CellValue = new CellValue(Utility.GetMessage("property"));
				cell6.DataType = CellValues.String;
				cell2 = cell6;
				row2.Append(cell2);
				Cell cell7 = new Cell();
				cell7.CellValue = new CellValue(Utility.GetMessage("compound_tube_no"));
				cell7.DataType = CellValues.String;
				cell2 = cell7;
				row2.Append(cell2);
				firstChild.Append(row2);
				IList<Well> list = experiment.Wells.Where((Well s) => s.Sample != null).ToList();
				MergeCells mergeCells = new MergeCells();
				mergeCells.Count = UInt32Value.FromUInt32((uint)list.Count);
				MergeCells mergeCells2 = mergeCells;
				foreach (Well well in list)
				{
					uint num2 = num;
					List<OpenXmlElement> list2 = new List<OpenXmlElement>();
					ObservableCollection<SampleTargetItem> items = well.Sample.Items;
					Func<SampleTargetItem, bool> predicate = (SampleTargetItem s) => s.TubeNo == well.MultiTubeID;
					foreach (SampleTargetItem item in (IEnumerable<SampleTargetItem>)(from s in items.Where(predicate)
						orderby s.ChannelNo
						select s).ToList())
					{
						Row row3 = new Row();
						row3.RowIndex = num++;
						row2 = row3;
						Cell cell8 = new Cell();
						cell8.DataType = CellValues.String;
						cell2 = cell8;
						if (num2 + 1 == num)
						{
							cell2.CellValue = new CellValue(well.CellName);
						}
						list2.Add(cell2);
						row2.Append(cell2);
						Cell cell9 = new Cell();
						cell9.CellValue = new CellValue(item.TubeNo.ToString());
						cell9.DataType = CellValues.String;
						cell2 = cell9;
						row2.Append(cell2);
						Cell cell10 = new Cell();
						cell10.CellValue = new CellValue(item.TargetName);
						cell10.DataType = CellValues.String;
						cell2 = cell10;
						row2.Append(cell2);
						Cell cell11 = new Cell();
						cell11.CellValue = new CellValue(Utility.GetMessage(item.SampleType.ToString()));
						cell11.DataType = CellValues.String;
						cell2 = cell11;
						row2.Append(cell2);
						Cell cell12 = new Cell();
						cell12.CellValue = new CellValue(item.Property);
						cell12.DataType = CellValues.String;
						cell2 = cell12;
						row2.Append(cell2);
						Cell cell13 = new Cell();
						cell13.CellValue = new CellValue(well.Sample.CompoundTubeNo);
						cell13.DataType = CellValues.String;
						cell2 = cell13;
						row2.Append(cell2);
						firstChild.Append(row2);
					}
					MergeCell mergeCell = new MergeCell();
					mergeCell.Reference = "A" + num2 + ":A" + (num - 1);
					mergeCells2.Append(mergeCell);
				}
				worksheet.Append(mergeCells2);
				worksheet.Save();
			}
		}

		public static void CreateNewExcel(string path, string sheetName)
		{
			using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook, true))
			{
				spreadsheetDocument.AddWorkbookPart();
				spreadsheetDocument.WorkbookPart.Workbook = new Workbook();
				spreadsheetDocument.WorkbookPart.AddNewPart<WorksheetPart>();
				spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet = new Worksheet();
				SheetData newChild = new SheetData();
				spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet.AppendChild(newChild);
				spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet.Save();
				spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
				spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild(new Sheet
				{
					Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(spreadsheetDocument.WorkbookPart.WorksheetParts.First()),
					SheetId = 1u,
					Name = sheetName
				});
				spreadsheetDocument.WorkbookPart.Workbook.Save();
			}
		}

		private static void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1)
		{
			Stylesheet stylesheet = new Stylesheet();
			stylesheet.MCAttributes = new MarkupCompatibilityAttributes
			{
				Ignorable = "x14ac"
			};
			Stylesheet stylesheet2 = stylesheet;
			stylesheet2.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
			stylesheet2.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
			Fonts fonts = new Fonts();
			fonts.Count = 2u;
			fonts.KnownFonts = true;
			Fonts fonts2 = fonts;
			Font font = new Font();
			FontSize fontSize = new FontSize();
			fontSize.Val = 11.0;
			FontSize fontSize2 = fontSize;
			Color color = new Color();
			color.Theme = 1u;
			Color color2 = color;
			FontName fontName = new FontName();
			fontName.Val = "宋体";
			FontName fontName2 = fontName;
			FontFamilyNumbering fontFamilyNumbering = new FontFamilyNumbering();
			fontFamilyNumbering.Val = 2;
			FontFamilyNumbering fontFamilyNumbering2 = fontFamilyNumbering;
			FontScheme fontScheme = new FontScheme();
			fontScheme.Val = FontSchemeValues.Minor;
			FontScheme fontScheme2 = fontScheme;
			font.Append(fontSize2);
			font.Append(color2);
			font.Append(fontName2);
			font.Append(fontFamilyNumbering2);
			font.Append(fontScheme2);
			Font font2 = new Font();
			FontSize fontSize3 = new FontSize();
			fontSize3.Val = 9.0;
			FontSize fontSize4 = fontSize3;
			FontName fontName3 = new FontName();
			fontName3.Val = "宋体";
			FontName fontName4 = fontName3;
			FontFamilyNumbering fontFamilyNumbering3 = new FontFamilyNumbering();
			fontFamilyNumbering3.Val = 3;
			FontFamilyNumbering fontFamilyNumbering4 = fontFamilyNumbering3;
			FontCharSet fontCharSet = new FontCharSet();
			fontCharSet.Val = 134;
			FontCharSet fontCharSet2 = fontCharSet;
			FontScheme fontScheme3 = new FontScheme();
			fontScheme3.Val = FontSchemeValues.Minor;
			FontScheme fontScheme4 = fontScheme3;
			font2.Append(fontSize4);
			font2.Append(fontName4);
			font2.Append(fontFamilyNumbering4);
			font2.Append(fontCharSet2);
			font2.Append(fontScheme4);
			fonts2.Append(font);
			fonts2.Append(font2);
			Fills fills = new Fills();
			fills.Count = 2u;
			Fills fills2 = fills;
			Fill fill = new Fill();
			PatternFill patternFill = new PatternFill();
			patternFill.PatternType = PatternValues.None;
			PatternFill patternFill2 = patternFill;
			fill.Append(patternFill2);
			Fill fill2 = new Fill();
			PatternFill patternFill3 = new PatternFill();
			patternFill3.PatternType = PatternValues.Gray125;
			PatternFill patternFill4 = patternFill3;
			fill2.Append(patternFill4);
			fills2.Append(fill);
			fills2.Append(fill2);
			Borders borders = new Borders();
			borders.Count = 1u;
			Borders borders2 = borders;
			Border border = new Border();
			LeftBorder leftBorder = new LeftBorder();
			RightBorder rightBorder = new RightBorder();
			TopBorder topBorder = new TopBorder();
			BottomBorder bottomBorder = new BottomBorder();
			DiagonalBorder diagonalBorder = new DiagonalBorder();
			border.Append(leftBorder);
			border.Append(rightBorder);
			border.Append(topBorder);
			border.Append(bottomBorder);
			border.Append(diagonalBorder);
			borders2.Append(border);
			CellStyleFormats cellStyleFormats = new CellStyleFormats();
			cellStyleFormats.Count = 1u;
			CellStyleFormats cellStyleFormats2 = cellStyleFormats;
			CellFormat cellFormat = new CellFormat();
			cellFormat.NumberFormatId = 0u;
			cellFormat.FontId = 0u;
			cellFormat.FillId = 0u;
			cellFormat.BorderId = 0u;
			CellFormat cellFormat2 = cellFormat;
			cellStyleFormats2.Append(cellFormat2);
			CellFormats cellFormats = new CellFormats();
			cellFormats.Count = 2u;
			CellFormats cellFormats2 = cellFormats;
			CellFormat cellFormat3 = new CellFormat();
			cellFormat3.NumberFormatId = 0u;
			cellFormat3.FontId = 0u;
			cellFormat3.FillId = 0u;
			cellFormat3.BorderId = 0u;
			cellFormat3.FormatId = 0u;
			CellFormat cellFormat4 = cellFormat3;
			CellFormat cellFormat5 = new CellFormat();
			cellFormat5.NumberFormatId = 0u;
			cellFormat5.FontId = 0u;
			cellFormat5.FillId = 0u;
			cellFormat5.BorderId = 0u;
			cellFormat5.FormatId = 0u;
			cellFormat5.ApplyAlignment = true;
			CellFormat cellFormat6 = cellFormat5;
			Alignment alignment = new Alignment();
			alignment.Horizontal = HorizontalAlignmentValues.Left;
			alignment.Vertical = VerticalAlignmentValues.Center;
			Alignment alignment2 = alignment;
			cellFormat6.Append(alignment2);
			cellFormats2.Append(cellFormat4);
			cellFormats2.Append(cellFormat6);
			CellStyles cellStyles = new CellStyles();
			cellStyles.Count = 1u;
			CellStyles cellStyles2 = cellStyles;
			CellStyle cellStyle = new CellStyle();
			cellStyle.Name = "Normal";
			cellStyle.FormatId = 0u;
			cellStyle.BuiltinId = 0u;
			CellStyle cellStyle2 = cellStyle;
			cellStyles2.Append(cellStyle2);
			DifferentialFormats differentialFormats = new DifferentialFormats();
			differentialFormats.Count = 0u;
			DifferentialFormats differentialFormats2 = differentialFormats;
			TableStyles tableStyles = new TableStyles();
			tableStyles.Count = 0u;
			tableStyles.DefaultTableStyle = "TableStyleMedium2";
			tableStyles.DefaultPivotStyle = "PivotStyleMedium9";
			TableStyles tableStyles2 = tableStyles;
			StylesheetExtensionList stylesheetExtensionList = new StylesheetExtensionList();
			StylesheetExtension stylesheetExtension = new StylesheetExtension();
			stylesheetExtension.Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}";
			StylesheetExtension stylesheetExtension2 = stylesheetExtension;
			stylesheetExtension2.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
			stylesheetExtensionList.Append(stylesheetExtension2);
			stylesheet2.Append(fonts2);
			stylesheet2.Append(fills2);
			stylesheet2.Append(borders2);
			stylesheet2.Append(cellStyleFormats2);
			stylesheet2.Append(cellFormats2);
			stylesheet2.Append(cellStyles2);
			stylesheet2.Append(differentialFormats2);
			stylesheet2.Append(tableStyles2);
			stylesheet2.Append(stylesheetExtensionList);
			workbookStylesPart1.Stylesheet = stylesheet2;
		}

		public static void SaveToExcel(string file, ExcelData data, int startMerger = 1)
		{
			using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(file, SpreadsheetDocumentType.Workbook))
			{
				WorkbookPart workbookPart = spreadsheetDocument.AddWorkbookPart();
				spreadsheetDocument.WorkbookPart.Workbook = new Workbook();
				spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
				WorkbookStylesPart workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>("rId5");
				GenerateWorkbookStylesPart1Content(workbookStylesPart);
				for (int i = 0; i < data.SheetDataList.Count; i++)
				{
					WorksheetPart worksheetPart = spreadsheetDocument.WorkbookPart.AddNewPart<WorksheetPart>();
					worksheetPart.Worksheet = new Worksheet();
					List<int> list = new List<int>();
					SheetData sheetData = new SheetData();
					ExcelSheetData excelSheetData = data.SheetDataList[i];
					List<List<string>> data2 = excelSheetData.Data;
					uint num = 1u;
					for (int j = 1; j < data2.Count; j++)
					{
						List<string> list2 = data2[j];
						Row row = new Row();
						row.RowIndex = num++;
						Row row2 = row;
						for (int k = 0; k < list2.Count; k++)
						{
							string text = list2[k];
							Cell cell = new Cell();
							cell.StyleIndex = 1u;
							cell.DataType = CellValues.String;
							Cell cell2 = cell;
							if (!string.IsNullOrEmpty(text))
							{
								cell2.CellValue = new CellValue(text);
							}
							row2.Append(cell2);
							if (k >= list.Count)
							{
								list.Add(4);
							}
							if (!string.IsNullOrEmpty(text) && (CellValues)cell2.DataType == CellValues.String)
							{
								int num2 = BytesConverter.GetBytes(text).Length;
								if (num2 > list[k])
								{
									list[k] = num2;
								}
							}
						}
						sheetData.Append(row2);
					}
					MergeCells mergeCells = new MergeCells();
					string text2 = null;
					int num3 = 0;
					int num4 = 0;
					for (int l = startMerger; l < data2.Count; l++)
					{
						if (data2[l].Count == 0)
						{
							continue;
						}
						if (l == startMerger)
						{
							text2 = data2[l][0];
							num3 = l;
						}
						else
						{
							if ((!string.IsNullOrEmpty(data2[l][0]) || l != data2.Count - 1) && (string.IsNullOrEmpty(data2[l][0]) || !(text2 != data2[l][0])))
							{
								continue;
							}
							num4 = ((!string.IsNullOrEmpty(data2[l][0]) || l != data2.Count - 1) ? (l - 1) : l);
							for (int m = 0; m < data2[0].Count; m++)
							{
								if (data2[0][m] == null)
								{
									string text3 = Utility.IndexToColumn(m);
									MergeCell mergeCell = new MergeCell();
									mergeCell.Reference = text3 + num3 + ":" + text3 + num4;
									mergeCells.Append(mergeCell);
								}
							}
							num3 = l;
							text2 = data2[l][0];
						}
					}
					worksheetPart.Worksheet.AppendChild(sheetData);
					if (mergeCells.HasChildren)
					{
						worksheetPart.Worksheet.Append(mergeCells);
					}
					worksheetPart.Worksheet.Save();
					spreadsheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild(new Sheet
					{
						Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
						SheetId = (uint)(i + 1),
						Name = excelSheetData.Name
					});
				}
				spreadsheetDocument.WorkbookPart.Workbook.Save();
			}
		}

		public static Hashtable ExcelToHashTable(string filePath)
		{
			Hashtable hashtable = new Hashtable();
			try
			{
				using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filePath, false))
				{
					WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
					List<string> sheetNames = GetSheetNames(workbookPart);
					foreach (string item in sheetNames)
					{
						WorkSheetToTable(workbookPart, hashtable, item);
					}
				}
			}
			catch (Exception ex)
			{
				Log.WriteLine(string.Format("{0}\t{1}", "读取语言文件失败!", ex.Message));
			}
			return hashtable;
		}

		private static List<string> GetSheetNames(WorkbookPart workBookPart)
		{
			List<string> list = new List<string>();
			Sheets sheets = workBookPart.Workbook.Sheets;
			foreach (Sheet item in sheets)
			{
				string text = item.Name;
				if (!string.IsNullOrEmpty(text))
				{
					list.Add(text);
				}
			}
			return list;
		}

		private static Hashtable WorkSheetToTable(WorkbookPart workBookPart, Hashtable hashTable, string sheetName)
		{
			IEnumerable<Row> workBookPartRows = GetWorkBookPartRows(workBookPart, sheetName);
			if (workBookPartRows == null || workBookPartRows.Count() <= 0)
			{
				return null;
			}
			foreach (Row item in workBookPartRows)
			{
				string key = string.Empty;
				string value = string.Empty;
				foreach (Cell item2 in item)
				{
					if (item2.CellReference.ToString().Contains("A"))
					{
						key = GetCellValue(item2, workBookPart);
					}
					else if (item2.CellReference.ToString().Contains(LanguageOption.VALUE_COLUMN))
					{
						value = GetCellValue(item2, workBookPart);
					}
				}
				if (hashTable.Contains(key))
				{
					hashTable[key] = value;
				}
				else
				{
					hashTable.Add(key, value);
				}
			}
			return hashTable;
		}

		private static IEnumerable<Row> GetWorkBookPartRows(WorkbookPart workBookPart, string sheetName)
		{
			IEnumerable<Row> enumerable = null;
			IEnumerable<Sheet> source = from s in workBookPart.Workbook.Descendants<Sheet>()
				where s.Name == sheetName
				select s;
			if (source.Count() == 0)
			{
				return null;
			}
			WorksheetPart worksheetPart = workBookPart.GetPartById(source.First().Id) as WorksheetPart;
			return worksheetPart.Worksheet.Descendants<Row>();
		}

		public static string GetCellValue(Cell cell, WorkbookPart workBookPart)
		{
			string empty = string.Empty;
			if (cell.ChildElements.Count == 0)
			{
				return empty;
			}
			string innerText2 = cell.CellReference.InnerText;
			string innerText = cell.CellValue.InnerText;
			empty = innerText;
			SharedStringTable sharedStringTable = workBookPart.SharedStringTablePart.SharedStringTable;
			try
			{
				EnumValue<CellValues> dataType = cell.DataType;
				if (dataType != null)
				{
					CellValues value = dataType.Value;
					if (value == CellValues.SharedString)
					{
						int i = int.Parse(innerText);
						empty = sharedStringTable.ChildElements[i].InnerText;
					}
					else
					{
						empty = innerText;
					}
				}
			}
			catch (Exception)
			{
				empty = "N/A";
			}
			return empty;
		}
	}
}
